﻿using System.Collections.Generic;
using Drill.Configuration;
using Drill.Core;
using Drill.Core.Utilities;
using Drill.Extensibility;

namespace Drill.TestHelpers
{
	public class TestUnityDependencyResolverFactory : IDependencyResolverFactory, IDrillBitFactory
	{
		/// <summary>
		/// Creates a new <see cref="IDependencyResolver"/> instance.
		/// </summary>
		/// <returns>A new <see cref="IDependencyResolver"/> instance.</returns>
		public IDependencyResolver CreateDependencyResolver()
		{
			const string assemblyQualifiedtypeName = "Drill.DrillBits.Unity.UnityDrillBit, Drill.DrillBits.Unity";

			IDrillBitInitContext initializationContext =
				new DrillBitInitContext
					{
						ConfigurationHelper =
							new ConfigurationHelper(
								new List<IRootPathProvider>
									{
										new ExecutingDirectoryRootPathProvider()
									})
					  , ConfigurationSources = new List<IConfigurationSource>()
					  , Name = "Unity"
					};

			return 
				AssemblyUtility.CreateInstance<IDependencyResolver>(
					assemblyQualifiedtypeName
				  , "Unity DrillBit"
				  , new object[] {initializationContext}
					);
		}

		/// <summary>
		/// Creates a new <see cref="IDrillBit"/> instance.
		/// </summary>
		/// <returns>A new <see cref="IDrillBit"/> instance.</returns>
		IDrillBit IDrillBitFactory.CreateDrillBit()
		{
			return ((IDependencyResolverFactory) this).CreateDependencyResolver() as IDrillBit;
		}
	}
}